package com.sqstudio.util.zip
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLRequest;
	import flash.net.URLStream;
	import flash.utils.IDataInput;
	import com.sqstudio.util.zip.zipsrc.ZipEntry;
	import com.sqstudio.util.zip.zipsrc.ZipFile;
	
	/**
	 *ZIP工具类 
	 * @author Nestor
	 * 
	 */
	public class ZipManger extends EventDispatcher
	{
		
		private var callBackFun:Function = null;
		public function ZipManger()
		{
			
		}
		
		/**
		 * 加载zip 文件
		 * @param fileUrl
		 * @param callBack  会返回数据（obj）
		 * 
		 */	
		public function load(fileUrl:String,callBack:Function):void{
			this.callBackFun = callBack;
			var urlStream:URLStream = new URLStream();
			urlStream.addEventListener(Event.COMPLETE, completeHandler);
			urlStream.load(new URLRequest(fileUrl));
		}
		
		private function completeHandler(evt:Event):void{
			var data:URLStream = URLStream(evt.target);
			var zipFile:ZipFile = new ZipFile(data);
			var zipFileData:Object;
			for each(var entry:String in zipFile.entries){
				var zipEntry:ZipEntry = zipFile.getEntry(String(entry));
				zipFileData = String(zipFile.getInput(zipEntry));
			}
			
			if(this.callBackFun != null){
				this.callBackFun(zipFileData);
				this.callBackFun = null;
			}
		}
	}
}